<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
   
      <!-- <el-form-item label="演练时间" prop="startTime">
        <el-date-picker
          v-model="bnTime"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
        >
        </el-date-picker>
      </el-form-item> -->
      <el-form-item label="演练标题" label-width="80px">
        <el-input
          v-model="queryParams.emName"
          placeholder="请输入演练标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
       <el-form-item label="演练时间" prop="startTime">
        <el-date-picker
          clearable
          v-model="queryParams.startTime"
          type="datetime"
          placeholder="请选择演练时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <!-- v-hasPermi="['app:vehicles:add']" 新增权限 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        >
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-tabs v-model="activeName">
      <el-tab-pane label="我发起的" name="first">
        <el-table :data="ListVehicles">
          <el-table-column type="selection" width="55" align="center" />
          <!-- <el-table-column label="${comment}" align="center" prop="id" /> -->
          <el-table-column label="演练标题" align="center" prop="emName" />
          <el-table-column label="演练目的" align="center" prop="target" />
          <el-table-column label="演练时间" align="center" prop="startTime">
            
          </el-table-column>
          <el-table-column label="参与部门" align="center" prop="deptName" />
          <el-table-column label="方案文件" align="center" prop="draftUrl">
            <template slot-scope="scope">
              <div v-if="scope.row.draftUrl">
                <el-button
                  v-if="gettp(scope.row.draftUrl) == 1"
                  size="mini"
                  type="text"
                  @click="look(scope.row.draftUrl)"
                  >查看</el-button
                >
                <el-button
                  v-if="gettp(scope.row.draftUrl) == 2"
                  size="mini"
                  type="text"
                  @click="download(scope.row.draftUrl)"
                  >下载</el-button
                >
              </div>
            </template>
          </el-table-column>

          <el-table-column label="发布时间" align="center" prop="createTime" />

          <el-table-column label="审核状态" align="center">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.approStatus == 1" type="warning">{{
                detailStatus[scope.row.approStatus]
              }}</el-tag>
              <el-tag v-if="scope.row.approStatus == 2" type="success">{{
                detailStatus[scope.row.approStatus]
              }}</el-tag>
              <el-tag v-if="scope.row.approStatus == 3" type="danger">{{
                detailStatus[scope.row.approStatus]
              }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="Details(scope.row)"
                >查看详细</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="ListVehiclestotal > 0"
          :total="ListVehiclestotal"
          :page.sync="queryParams.currentPage"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-tab-pane>
      <el-tab-pane label="待审核" name="second">
        <el-table :data="listByMyslef">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column type="selection" width="55" align="center" />
          <!-- <el-table-column label="${comment}" align="center" prop="id" /> -->
          <el-table-column label="演练标题" align="center" prop="emName" />
          <el-table-column label="演练目的" align="center" prop="target" />
          <el-table-column label="参与部门" align="center" prop="deptName" />
          <el-table-column label="方案文件" align="center" prop="draftUrl">
            <template slot-scope="scope">
              <div v-if="scope.row.draftUrl">
                <el-button
                  v-if="gettp(scope.row.draftUrl) == 1"
                  size="mini"
                  type="text"
                  @click="look(scope.row.draftUrl)"
                  >查看</el-button
                >
                <el-button
                  v-if="gettp(scope.row.draftUrl) == 2"
                  size="mini"
                  type="text"
                  @click="download(scope.row.draftUrl)"
                  >下载</el-button
                >
              </div>
            </template>
          </el-table-column>
          <!-- <el-table-column label="通知文件" align="center" prop="isCheck">
            <template slot-scope="scope">
              <div v-if="scope.row.note">
                <el-button
                  v-if="gettp(scope.row.note) == 1"
                  size="mini"
                  type="text"
                  @click="look(scope.row.note)"
                  >查看</el-button
                >
                <el-button
                  v-if="gettp(scope.row.note) == 2"
                  size="mini"
                  type="text"
                  @click="download(scope.row.note)"
                  >下载</el-button
                >
              </div>
            </template>
          </el-table-column> -->
          <!-- <el-table-column label="车牌号码" align="center" prop="carNo" /> -->
          <el-table-column label="演练时间" align="center" prop="createTime" />

          <el-table-column label="审核状态" align="center">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.approStatus == 1" type="warning">{{
                detailStatus[scope.row.approStatus]
              }}</el-tag>
              <el-tag v-if="scope.row.approStatus == 2" type="success">{{
                detailStatus[scope.row.approStatus]
              }}</el-tag>
              <el-tag v-if="scope.row.approStatus == 3" type="danger">{{
                detailStatus[scope.row.approStatus]
              }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="myDetails(scope.row.flowNo, scope.row.id)"
                >去审核</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="listByMysleftotal > 0"
          :total="listByMysleftotal"
          :page.sync="quParams.pageNum"
          :limit.sync="quParams.pageSize"
          @pagination="getList"
        />
      </el-tab-pane>
    </el-tabs>

    <!-- 添加外来车辆管理对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="620px"
      append-to-body
      @close="openClose"
      :close-on-click-modal="false"
    >
      <div class="top">
        <el-steps :space="200" :active="stepIndex" finish-status="success">
          <el-step title="数据录入"></el-step>
          <el-step title="选择审批人"></el-step>
          <el-step title="发起审核"></el-step>
        </el-steps>
      </div>
      <div class="contentForm" v-if="stepIndex == 0">
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="演练名称" prop="emName">
            <el-input v-model="form.emName" placeholder="请输入演练名称" />
          </el-form-item>
          <el-form-item label="演练目的" prop="target">
            <el-input v-model="form.target" placeholder="请输入应急目标" />
          </el-form-item>
          <el-form-item label="演练时间" prop="startTime">
            <el-date-picker
              v-model="form.startTime"
              type="datetime"
              placeholder="选择日期时间"
              value-format="yyyy-MM-dd HH:mm:ss"
              default-time="12:00:00"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="方案文件" prop="draftUrl">
            <FileUpload
              v-model="form.draftUrl"
              @input="draftUrlupImage"
              :limit="5"
            ></FileUpload>
          </el-form-item>
          <el-form-item label="演练部门" prop="deptName">
            <!-- <el-input v-model="form.deptName" placeholder="请输入事由" /> -->

            <!--                   @change="cascaderChange" -->
            <el-cascader
              placeholder="部门"
              v-model="form.deptName"
              :options="deptOptions"
              :props="{ value: 'label', multiple: true, emitPath: false }"
              :show-all-levels="false"
              filterable
            ></el-cascader>
          </el-form-item>
          <!--               multiple
              collapse-tags -->
          <el-form-item label="参会人员" prop="emergUserList">
            <el-select
              v-model="form.emergUserList"
              filterable
              multiple
              value-key="userId"
            >
              <el-option
                v-for="item in userSelectList"
                :key="item.userId"
                :label="item.nickName"
                :value="
                  clonePerson({ nickName: item.nickName, userId: item.userId })
                "
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="子项目" prop="projectList">
            <el-row v-for="(item, index) in form.projectList" :key="index">
              <el-col :span="9"
                ><el-input v-model="item.project" placeholder="子项目名称"
              /></el-col>
              <el-col :span="9">
                <el-select
                  v-model="item.userId"
                  collapse-tags
                  filterable
                  placeholder="负责人"
                >
                  <el-option
                    v-for="item in userSelectList"
                    :key="item.userId"
                    :label="item.nickName"
                    :value="item.userId"
                  ></el-option>
                </el-select>
              </el-col>
              <el-col :span="6">
                <el-button
                  type="primary"
                  v-if="index + 1 == form.projectList.length"
                  icon="el-icon-plus"
                  @click="projectListAdd(form.projectList.length)"
                ></el-button>
                <el-button
                  type="danger"
                  v-if="index !== 0"
                  icon="el-icon-delete"
                  @click="projectListPcc(item, index)"
                ></el-button>
              </el-col>
            </el-row>
          </el-form-item>
        </el-form>
      </div>
      <div class="contentForm" v-if="stepIndex == 1">
        <div class="topSearch">
          <el-input
            v-model="userPage.userName"
            placeholder="请输入姓名查询"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 10px; height: 40px"
          />
          <el-button
            @click="userSearch"
            type="primary"
            style="margin-bottom: 17px; height: 33px"
            >搜索</el-button
          >
        </div>
        <div class="userContent">
          <el-tree
            :data="deptOptions"
            :props="defaultProps"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            ref="tree"
            node-key="id"
            default-expand-all
            highlight-current
            @node-click="handleNodeClick"
          />

          <div class="userList">
            <span
              v-for="item in userList"
              :key="item.userId"
              @click="addUser(item)"
              >{{ item.nickName }}</span
            >
          </div>

          <div class="userFooter">
            <span @click="userFooterbefor()">上一页</span>
            <span @click="userFooternext()">下一页</span>
          </div>
        </div>
        <el-divider>审批人</el-divider>
        <div class="spUser">
          <span v-for="item in checkUserList" :key="item.userId"
            >{{ item.nickName
            }}<i class="close el-icon-close" @click="userClose(item.userId)"></i
          ></span>
        </div>

        <svg
          t="1702351083987"
          class="icon"
          viewBox="0 0 34578 1024"
          version="1.1"
          xmlns="http://www.w3.org/2000/svg"
          p-id="5820"
          width="200"
          height="5"
        >
          <path
            d="M0.98794 853.827303h32873.7096v169.184757H0.98794z m32873.7096-853.580318l1704.196816 1022.765075h-1704.196816z m0 0"
            fill="#13227a"
            p-id="5821"
          ></path>
        </svg>
        <span>将按照此顺序进行审批</span>
      </div>
      <div class="contentForm" v-if="stepIndex == 2">
        <el-divider>演练信息</el-divider>
        <el-descriptions>
          <el-descriptions-item label="演练名称">{{
            form.emName
          }}</el-descriptions-item>
          <el-descriptions-item label="演练时间">{{
            form.startTime
          }}</el-descriptions-item>
        </el-descriptions>
        <el-divider>演练部门</el-divider>
        <span
          style="margin: 10px"
          v-for="(item, index) in form.deptName"
          :key="index"
          >{{ item }}</span
        >
        <el-divider>参会人员</el-divider>
        <!-- {{form.emergUserList}} -->
        <span
          style="margin: 10px"
          v-for="item in form.emergUserList"
          :key="item.userId"
          >{{ item.nickName }}</span
        >
        <el-divider>审批人</el-divider>
        <span v-for="item in checkUserList" :key="item.userId"
          >{{ item.nickName
          }}<i class="close el-icon-close" @click="userClose(item.userId)"></i
        ></span>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="stepIndex != 0" @click="beforTip"
          >上一步</el-button
        >
        <el-button type="primary" v-if="stepIndex != 2" @click="nextTip"
          >下一步</el-button
        >
        <el-button type="primary" v-else @click="submit">提交审核</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 详情弹出框 -->
    <el-dialog
      title="详情"
      :visible.sync="detailOpen"
      width="1100px"
      append-to-body
    >
      <el-divider>演练信息</el-divider>
      <el-descriptions>
        <el-descriptions-item label="演练名称">{{
          ditailList.emName
        }}</el-descriptions-item>
        <el-descriptions-item label="演练时间">{{
          ditailList.startTime
        }}</el-descriptions-item>
      </el-descriptions>
      <el-divider>演练部门</el-divider>
      <span v-for="(item, index) in ditailList.deptName" :key="index">{{
        item
      }}</span>
      <el-divider>参会人员</el-divider>
      <!-- {{form.emergUserList}} -->
      <span
        style="margin: 10px"
        v-for="item in ditailList.emergUserList"
        :key="item.userId"
        >{{ item.nickName }}</span
      >
      <el-divider>子项目</el-divider>
      <!-- <span
          style="margin: 10px"
          v-for="item in ditailList.emergUserList"
          :key="item.flowNo"
          >{{ item.project }}</span
        > -->
      <el-table :data="ditailList.flowDetails">
        <el-table-column label="顺序" align="center" prop="sort" />
        <el-table-column label="项目内容" align="center" prop="project" />

        <el-table-column label="完成情况" align="center" prop="remark">
          <template slot-scope="scope">
            {{ scope.row.isOk == 0 ? "未完成" : "已完成" }}
          </template>
        </el-table-column>
        <el-table-column label="负责人" align="center" prop="nickName" />
      </el-table>
      <el-divider>审核信息</el-divider>
      <el-table :data="ditailList.flowDetails">
        <el-table-column label="审核人" align="center" prop="name" />
        <el-table-column label="审核顺序" align="center" prop="sort" />
        <el-table-column label="审核状态" align="center" prop="status">
          <template slot-scope="scope">
            {{ myStatus[scope.row.status] }}
          </template>
        </el-table-column>
        <el-table-column label="审核意见" align="center" prop="content">
        </el-table-column>
        <el-table-column label="审核时间" align="center" prop="auditTime" />
        <el-table-column label="备注" align="center" prop="remark" />
        <el-table-column label="签名" align="center" prop="sign">
          <template slot-scope="scope">
            <!-- {{scope.row.sign}} -->
            <img
              v-if="scope.row.sign"
              style="display: block; width: 80px; height: 40px"
              :src="scope.row.sign"
            />
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <!-- 待我审核弹出框 -->
    <el-dialog :visible.sync="mydetailOpen" width="700px" append-to-body>
      <el-divider>演练信息</el-divider>
      <el-form ref="form" :model="myForm" :rules="myRules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="审核" prop="thing">
              <el-switch
                v-model="myForm.status"
                active-color="#13ce66"
                inactive-color="#ff4949"
                :active-value="3"
                :inactive-value="4"
                @change="ccccccccc"
                active-text="同意"
                inactive-text="不同意"
              >
              </el-switch>

              <!-- <el-select v-model="myForm.status" placeholder="请选择">
                  <el-option label="通过" :value="3" />
                  <el-option label="不通过" :value="4" />
                </el-select> -->
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="签名" prop="thing">
              <div
                @click="signLog = true"
                style="width: 200px; background-color: #d9d9d9"
              >
                <el-image
                  :src="signinimg"
                  style="
                    width: 200px;
                    height: 100px;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    color: #999;
                  "
                >
                  <div slot="error">点击签名</div>
                </el-image>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="16">
            <el-form-item label="审核意见" prop="thing"
              ><el-input v-model="myForm.content" placeholder="请输入意见"
            /></el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <el-button type="primary" @click="mySunbit()">提交</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <!-- 批准出矿弹出框 -->
    <el-dialog :visible.sync="outOpen" width="700px" append-to-body>
      <el-divider>离场审批</el-divider>
      <el-form ref="form" :model="outForm" :rules="outRules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="离场审批" prop="thing">
              <el-select v-model="outForm.flag" placeholder="请选择">
                <el-option label="可以出场" :value="1" />
                <el-option label="禁止出厂" :value="0" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="离场时间" prop="thing">
              <el-date-picker
                v-model="outForm.departureTime"
                type="datetime"
                placeholder="选择日期时间"
                value-format="yyyy-MM-dd HH:mm:ss"
                default-time="12:00:00"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item>
              <el-button type="primary" @click="permitOut()">提交</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <!--签名 -->
    <el-dialog title="电子签名" :visible.sync="signLog" width="700px">
      <signinDia @setsignin="setsignin" :fileName="'sign'"></signinDia>
    </el-dialog>
    <el-dialog :visible.sync="mydetailOpen" width="700px" append-to-body>
      <!-- <el-divider>隐患信息</el-divider> -->
      <!-- <el-descriptions>
        <el-descriptions-item label="发现问题">{{
          mydetailData.desci
        }}</el-descriptions-item>
        <el-descriptions-item label="检查人">{{
          mydetailData.inspectedUsers
        }}</el-descriptions-item>
        <el-descriptions-item label="隐患部位">{{
          mydetailData.position
        }}</el-descriptions-item>
        <el-descriptions-item label="隐患等级">{{
          mydetailData.level == 1 ? "一般隐患" : "重大隐患"
        }}</el-descriptions-item>
        <el-descriptions-item label="隐患图片">

        </el-descriptions-item>
      </el-descriptions> -->
      <el-divider>审批信息</el-divider>
      <!-- <el-image v-for="(item,index) in mydetailData.photo.split(',')" :key="index" style="width: 100px; height: 100px" :src="item" fit="fill"></el-image> -->

      <!-- 审批信息 -->
      <el-form ref="form" :model="myForm" :rules="myRules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="审核" prop="thing">
              <el-switch
                v-model="myForm.status"
                active-color="#13ce66"
                inactive-color="#ff4949"
                :active-value="3"
                :inactive-value="4"
                active-text="同意"
                inactive-text="不同意"
              >
              </el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="签名" prop="thing">
              <div
                @click="signLog = true"
                style="width: 200px; background-color: #d9d9d9"
              >
                <el-image
                  :src="signinimg"
                  style="
                    width: 200px;
                    height: 100px;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    color: #999;
                  "
                >
                  <div slot="error">点击签名</div>
                </el-image>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="审核意见" prop="thing"
              ><el-input v-model="myForm.content" placeholder="请输入意见"
            /></el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item>
              <el-button type="primary" @click="mySunbit()">提交</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <preview-content v-if="showType" :previewMsg="previewMsg"></preview-content>
  </div>
</template>
<script>
import {
  listVehicles,
  listByMyslef,
  vehicles,
  myVehicles,
  vehiclesUpdate,
} from "@/api/system/emerg";
import { deptTreeSelect, listUser } from "@/api/system/user";
//import { listUser } from "@/api/system/user";
import cache from "@/plugins/cache";
import signinDia from "@/components/signFont/index.vue";
import { downloadFile } from "@/utils/download.js";
import PreviewContent from "@/components/PreviewContent/PreviewContent.vue";

export default {
  components: {
    signinDia,
    PreviewContent,
  },
  name: "Vehicles",
  data() {
    return {
      showType: true,
      previewMsg: {
        dialogTableVisible: false,
        fileType: "",
        iframeUrl: "",
      },
      signinimg: null,
      signLog: false,
      stepIndex: 0,
      userId: cache.session.getJSON("userId"),
      ListVehicles: [],
      listByMyslef: [],
      FlowList: [],
      activeName: "first",
      myStatus: {
        1: "审核中",
        2: "待我审核",
        3: "通过",
        4: "驳回",
      },
      detailStatus: {
        1: "待审核",
        2: "通过",
        3: "驳回",
        4: "撤销",
      },

      deptOptions: null,
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 部门名称
      deptName: undefined,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      ListVehiclestotal: 0,
      listByMysleftotal: 0,
      FlowListtotal: 0,
      // 外来车辆管理表格数据
      // vehiclesList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      detailOpen: false,
      mydetailOpen: false,
      outOpen: false,
      mydetailData: {},
      ditailList: [],
      // 是否离场时间范围
      daterangeTime: [],
      // 查询参数

      bnTime: [],
      queryParams: {
        currentPage: 1,
        pageSize: 10,
        beginStartTime: null,
        endStartTime: null,
        emName: null,
        
      },
      quParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      myForm: {
        flowNo: null,
        status: 3,
        auditUserId: null,
        sign: null,
        id: null,
        content: "",
      },
      outForm: {
        flowNo: null,
        flag: 1,
        departureTime: null,
      },
      // 表单校验
      rules: {},
      myRules: {},
      outRules: {},
      //人员数据
      userList: [],

      checkUserList: [],
      userPage: {
        pageNum: 1,
        pageSize: 12,
        deptId: null,
        userName: "",
      },
      deptOptions: [],
      userSelectList: [],
    };
  },
  created() {
    this.getList();
    this.getDeptTree();
    this.getUserList();
    this.reset();
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    },
  },
  methods: {
    clonePerson(value) {
      // 使用深拷贝创建独立的对象
      return { ...value };
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then((response) => {
        this.deptOptions = response.data;
      });
    },
    // 查询人员
    userSearch() {
      listUser(this.userPage).then((res) => {
        this.userPage.deptId = null;
        // this.userPage.pageNum = 1;
        if (res.code == 200) {
          this.userList = res.rows;
          this.total = res.total;
        }
      });
    },
    cascaderChange(data) {
      console.log(data);
      // pageNum=1&pageSize=6&peopleType=1&deptId=105
      listUser({
        deptId: data[data.length - 1],
        // pageNum: 1,
        // pageSize: 1,
        peopleType: 1,
      }).then((res) => {
        this.userSelectList = res.rows;
      });
    },
    getUserList() {
      listUser({
        pageNum: 1,
        pageSize: 999,
      }).then((res) => {
        this.userSelectList = res.rows;
      });
    },
    setsignin(img) {
      this.signinimg = img;
      this.signLog = false;
      this.myForm.sign = img;
    },
    /** 查询外来车辆管理列表 */
    getList() {
      this.getListVehicles();
      this.getListByMyslef();
      //   this.getFlowList();
    },
    ccccccccc(a) {
      console.log(a);
    },
    // 查看演练详细
    Details(data) {
      console.log(data);
      this.detailOpen = true;
      this.ditailList = data;
    },
    //待我审核详细

    myDetails(flowNo, id) {
      this.mydetailOpen = true;

      this.myForm.flowNo = flowNo;
      this.myForm.id = id;
      //vehiclesQuery(flowNo).then((res) => {
      //  console.log(res);
      //  this.mydetailOpen = true;
      //  this.mydetailData = res.data;
      //});
    }, //
    // 批准出矿
    out(flowNo) {
      this.outOpen = true;
      this.outForm.flowNo = flowNo;
    },
    // 添加框关闭
    openClose() {
      this.checkUserList = [];
      this.stepIndex = 0;
      this.reset();
    },

    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then((response) => {
        this.deptOptions = response.data;
      });
    },
    // 查询人员
    userSearch() {
      listUser(this.userPage).then((res) => {
        this.userPage.deptId = null;
        // this.userPage.pageNum = 1;
        if (res.code == 200) {
          this.userList = res.rows;
          this.total = res.total;
        }
      });
    },
    // 人员上一页
    userFooterbefor() {
      if (this.userPage.pageNum >= 2) {
        console.log(this.userPage.pageNum);
        this.userPage.pageNum--;
        console.log(this.userPage.pageNum);
        this.userSearch();
      } else {
        this.$message("已经是第一页了");
      }
    },
    // 人员下一页

    userFooternext() {
      if (this.userPage.pageNum < Math.ceil(this.total / 12)) {
        this.userPage.pageNum++;
        console.log(this.userPage.pageNum);
        this.userSearch();
      } else {
        this.$message("已经是最后一页了");
      }
    },
    //添加审批人
    addUser(item) {
      if (
        JSON.stringify(this.checkUserList).indexOf(JSON.stringify(item)) === -1
      ) {
        this.checkUserList.push(item);
      } else {
        this.$message.error("该审批人已经存在");
      }
    },
    // 删除审批用户
    userClose(id) {
      this.checkUserList.some((item, i) => {
        if (item.userId === id) {
          this.checkUserList.splice(i, 1);
        }
      });
    },
    // 提交审批
    submit() {
      let data = { ...this.form };
      data.userId = this.userId;
      data.type = 7;

      if (data.deptName != null) {
        data.deptName = data.deptName.join();
      }
      this.checkUserList.forEach((item, index) => {
        data.flowDetails.push({ auditUserId: item.userId, sort: index + 1 });
      });
      //   data.emergUserList = [];
      //   data.projectList = []; //{ project  子项目名,userId 责任人}

      console.log(data);

      vehicles(data).then((res) => {
        if (res.code == 200) {
          this.$modal.msgSuccess("提交成功");
          this.open = false;
          this.reset();
          this.stepIndex = 0;
          this.checkUserList = [];
          this.getList();
        } else {
          this.open = false;
          this.reset();
          this.stepIndex = 0;
          this.checkUserList = [];
          this.getList();
          this.$message.error("提交失败");
        }
      });
    },
    // 我的审核
    mySunbit() {
      this.myForm.auditUserId = this.userId;
      myVehicles(this.myForm).then((res) => {
        if (res.code == 200) {
          this.$message("审批完成");
        } else {
          this.$message.error("失败");
        }
        this.mydetailOpen = false;
        this.getList();
      });
    },
    // 出厂审批
    permitOut() {
      vehiclesUpdate(this.outForm).then((res) => {
        console.log(res);
        if (res.code == 200) {
          this.$modal.msgSuccess("审批成功");
        }
        this.outOpen = false;
        this.outForm = {
          flowNo: null,
          flag: 1,
          departureTime: null,
        };
        this.getList();
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.userPage.deptId = data.id;

      this.userPage.pageNum = 1;

      this.userSearch();
    },

    // 我发起的
    async getListVehicles() {
      this.queryParams.beginStartTime = this.bnTime[0];
      this.queryParams.endStartTime = this.bnTime[1];
      await listVehicles({
        ...this.queryParams,
        userId: this.userId,
        type: 7,
      }).then((res) => {
        console.log(res, "我发起的");
        if (res.success) {
          this.ListVehicles = res.data.list;
          this.ListVehiclestotal = res.data.total;
        }
      });
    },

    //待审核
    async getListByMyslef() {
      this.queryParams.beginStartTime = this.bnTime[0];
      this.queryParams.endStartTime = this.bnTime[1];
      await listByMyslef({ ...this.quParams, userId: this.userId }).then(
        (res) => {
          console.log(res, "待审核的");
          this.listByMyslef = res.rows;
          this.listByMysleftotal = res.total;
        }
      );
    },
    // 已通过
    // async getFlowList() {
    //   await flowList({ ...this.queryParams, approStatus: 2, type: 1 }).then(
    //     (res) => {
    //       console.log(res, "已通过的");
    //       if (res.code == 200) {
    //         this.FlowList = res.rows;
    //         this.FlowListtotal = res.total;
    //       }
    //     }
    //   );
    // },
    //上一步
    beforTip() {
      this.stepIndex--;
    },
    //下一步
    nextTip() {
      if (this.stepIndex == 0) {
        this.getDeptTree();
      } else if (this.stepIndex == 2) {
        return;
      }
      this.stepIndex++;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        userId: this.userId,
        type: 7,
        emName: null,
        draftUrl: null,
        target: null,
        startTime: null,
        deptName: null,
        flowDetails: [],
        emergUserList: [],
        projectList: [
          {
            project: null,
            userId: null,
          },
        ],
      };
      this.resetForm("form");
    },
    projectListAdd() {
      this.form.projectList.push({
        project: null,
        userId: null,
      });
    },
    projectListPcc(item, index) {
      this.form.projectList.splice(index, 1);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      //this.bnTime = [];
      this.resetForm("queryForm");
      // (this.queryParams = {
      //   pageNum: 1,
      //   pageSize: 10,
      //   beginStartTime: null,
      //   endStartTime: null,
      // }),
      this.queryParams.emName = null;
      this.handleQuery();
      this.getList();
    },
    // 多选框选中数据
    // handleSelectionChange(selection) {
    // this.ids = selection.map((item) => item.id);
    // this.single = selection.length !== 1;
    // this.multiple = !selection.length;
    // },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加应急演练方案";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getVehicles(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改应急演练方案";
      });
    },
    /** 提交按钮 */
    //submitForm() {
    //  this.$refs["form"].validate((valid) => {
    //    if (valid) {
    //      if (this.form.id != null) {
    //        updateVehicles(this.form).then((response) => {
    //          this.$modal.msgSuccess("修改成功");
    //          this.open = false;
    //          this.getList();
    //        });
    //      } else {
    //        addVehicles(this.form).then((response) => {
    //          this.$modal.msgSuccess("新增成功");
    //          this.open = false;
    //          this.getList();
    //        });
    //      }
    //    }
    //  });
    //},
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除外来车辆管理编号为"' + ids + '"的数据项？')
        .then(function () {
          return delVehicles(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "app/vehicles/export",
        {
          ...this.queryParams,
        },
        `vehicles_${new Date().getTime()}.xlsx`
      );
    },
    download(value) {
      if (value.indexOf(",") >= 0) {
        let split = value.split(",");
        for (var i = 0; i < split.length; i++) {
          if (split[i] != "") {
            let num = split[i].lastIndexOf(".");
            let dis = split[i].substring(num + 1, num + 4);

            if (dis == "pdf" || dis == "PDF") {
              downloadFile(split[i], "a");
            } else {
              downloadFile(split[i], "iframe");
            }
          }
        }
      } else {
        let num = value.lastIndexOf(".");
        let dis = value.substring(num + 1, num + 4);
        if (dis == "pdf" || dis == "PDF") {
          downloadFile(value, "a");
        } else {
          downloadFile(value, "iframe");
        }
      }
    },
    gettp(v) {
      let type = null;
      if (v.includes(",")) {
        let list = v.split(",");
        list.forEach((item) => {
          type = this.getFileType(item);
        });
      } else {
        type = this.getFileType(v);
      }
      if (type == "pdf" || type == "txt") {
        return 1;
      } else {
        return 2;
      }
    },
    getFileType(url) {
      let pdfReg = /^.+(\.pdf)$/;
      let txtReg = /^.+(\.txt)$/;
      let wordReg = /^.+(\.doc|\.docx)$/;
      let excelReg = /^.+(\.xls|\.xlsx)$/;
      let jpgReg = /^.+(\.png|\.jpg|\.jpeg|\.bmp)$/;
      if (pdfReg.test(url)) {
        return "pdf";
      }
      if (txtReg.test(url)) {
        return "txt";
      }
      if (wordReg.test(url)) {
        return "word";
      }
      if (excelReg.test(url)) {
        return "excel";
      }
      if (jpgReg.test(url)) {
        return "picture";
      }
    },
    look(v) {
      this.showType = false;
      this.$nextTick(() => {
        this.showType = true;
      });
      let list = v.split(",");
      this.previewMsg.dialogTableVisible = true;
      this.previewMsg.iframeUrl = list[0];
    },
    draftUrlupImage(e) {
      this.form.draftUrl = e;
    },
  },
};
</script>
  <style lang='scss' scoped>
.el-tree {
  width: 30%;
}
.topSearch {
  display: flex;
  align-items: center;
}
.userContent {
  display: flex;
}
.userList {
  display: inline-grid;
  grid-template-columns: 100px 100px 100px;
  // grid-template-rows: 50px 50px;
  grid-gap: 5px;
  width: 70%;
  height: 100%;
  span {
    // width: 25%;
    padding: 8px;
    text-align: center;
    background-color: #ccc;
  }
}

.userFooter {
  position: absolute;
  right: 0;
  top: 500px;
  span {
    margin: 20px;
    color: #1890ff;
    cursor: pointer;
  }
}
.spUser {
  display: flex;
  span {
    position: relative;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: #27aa07;
    color: aliceblue;
    margin: 6px;
    text-align: center;
    line-height: 50px;

    .close {
      position: absolute;
      color: #000;
      top: 0;
      right: -5px;
      font-weight: 700;
      cursor: pointer;
      display: none;
    }
  }
  span:hover .close {
    display: block;
  }
}
</style>